package zhihuilan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import zhihuilan.dto.MyCircleDto;
import zhihuilan.entity.MyFactoryFav;

import java.util.List;

@Mapper
public interface MyFactoryFavMapper extends BaseMapper<MyFactoryFav> {

    @Select({" <script>  select b.*,c.headimgurl as staff_logo,c.logo as staff_headimgurl,c.title as staff_title,c.lat as staff_lat,c.lng staff_lng,c.address as staff_address,c.address1 as staff_address1,c.address2 as staff_address2,c.region as staff_region\n" +
            "    from my_factory_fav a right JOIN my_circle b on a.fav_staffid = b.staff_id left JOIN my_staff c on b.staff_id = c.id \n" +
            " where a.type = 0 and b.status = 1 and a.staffid =#{staffId} \n" +
            " <when test='isVideo'> " +
            "  and b.utype =1 \n" +
            " </when> " +
            " <when test='!isVideo'> " +
            "  and b.utype !=1 \n" +
            " </when> " +
            " <when test='regionLevel==1'> " +
            "  and COALESCE(c.districtid2,b.districtid2) =#{regionCode} \n" +
            " </when> " +
            " <when test='regionLevel==2'> " +
            "  and COALESCE(c.districtid1,b.districtid1) =#{regionCode} \n" +
            " </when> " +
            " <when test='regionLevel==3'> " +
            "  and COALESCE(c.districtid,b.districtid) =#{regionCode} \n" +
            " </when> " +
            " order by b.create_time desc LIMIT #{page},#{pageSize} " +
            " </script>"})
    List<MyCircleDto> selectPageListToCircle(@Param("page") Long page, @Param("pageSize") Long pageSize, @Param("staffId") Integer staffId, @Param("regionCode") String regionCode, @Param("regionLevel") Integer regionLevel,@Param("isVideo") Boolean isVideo);

    @Select({" <script>  select count(b.id) as cnt " +
            "    from my_factory_fav a right JOIN my_circle b on a.fav_staffid = b.staff_id left JOIN my_staff c on b.staff_id = c.id \n" +
            " where a.type = 0 and b.status = 1 and a.staffid =#{staffId} \n" +
            " <when test='isVideo'> " +
            "  and b.utype =1 \n" +
            " </when> " +
            " <when test='!isVideo'> " +
            "  and b.utype !=1 \n" +
            " </when> " +
            " <when test='regionLevel==1'> " +
            "  and COALESCE(c.districtid2,b.districtid2) =#{regionCode} \n" +
            " </when> " +
            " <when test='regionLevel==2'> " +
            "  and COALESCE(c.districtid1,b.districtid1) =#{regionCode} \n" +
            " </when> " +
            " <when test='regionLevel==3'> " +
            "  and COALESCE(c.districtid,b.districtid) =#{regionCode} \n" +
            " </when> " +
            " order by b.create_time desc " +
            " </script>"})
    Long selectCountToCircle(@Param("staffId") Integer staffId, @Param("regionCode") String regionCode, @Param("regionLevel") Integer regionLevel,@Param("isVideo") Boolean isVideo);


}
